/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.math;

/**
 *
 * @author pson
 */
public class Vector3 {
    public float x;
    public float y;
    public float z;

    public Vector3() {
        x = 0;
        y = 0;
        z = 0;
    }

    public Vector3(float x, float y, float z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    
    public Vector3(Vector3 v) {
        x = v.x;
        y = v.y;
        z = v.z;
    }
    
    public void set(float x, float y, float z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    
    public float[] toArray() {
        return new float[] {x, y, z};
    }
    
    public float lengthSquared() {
        return x*x + y*y + z*z;
    }
    
    public float length() {
        return (float)Math.sqrt(lengthSquared());
    }
    
    public Vector3 normalised() {
        float l = length();
        return new Vector3(x / l, y / l, z / l);
    }
    
    public Vector3 add(Vector3 v) {
        return new Vector3(x + v.x, y + v.y, z + v.z);
    }
    
    public Vector3 subtract(Vector3 v) {
        return new Vector3(x - v.x, y - v.y, z - v.z);
    }
    
    public Vector3 multiply(float v) {
        return new Vector3(x * v, y * v, z * v);
    }
    
    public Vector3 multiply(Vector3 v) {
        return new Vector3(x * v.x, y * v.y, z * v.z);
    }
    
    public Vector3 divide(float v) {
        return new Vector3(x / v, y / v, z / v);
    }
    
    public Vector3 divide(Vector3 v) {
        return new Vector3(x / v.x, y / v.y, z / v.z);
    }
    
    public float dot(float f) {
        return x*f + y*f + z*f;
    }
    
    public float dot(Vector3 v) {
        return x*v.x + y*v.y + z*v.z;
    }
    
    public boolean equals(Vector3 v) {
        return x == v.x && y == v.y && z == v.z;
    }
    
    public Vector3 cross(Vector3 v) {
        return new Vector3(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
    }
    
    public Vector3 inversed() {
        return new Vector3(-x, -y, -z);
    }
    
}
